<?php


namespace App\Http\Controllers\TransactionDetail;
use App\Exceptions\APIHttpException;
use App\Enum\APIEnum;
use App\Http\Library\Paas;
use App\Http\Controllers\Controller;
use App\Http\Model\TransactionDetail\ClassTransactionDetailModel;
use \App\Job\PfsHeadAddclassincrementJob;

use App\Http\Model\Common\BusinessModel;
use App\Http\Model\Auth\AuthModel;
use App\Http\Middleware\Auth;

class ClassTransactionDetail extends Controller
{
    /*
     * 2.1-班级交易明细
     * {
        "aaa": 111, "bbb": "222ssss",
        "page":1,"pagesize":10,
        "class_name":"22","city_name":"北京市"
        }
     *
    */
    public function index(){
        $input = $this->_auth();
        $func = __FUNCTION__;
        $ret = ClassTransactionDetailModel::$func($input);
        return APIHttpException::success($ret);
    }
    /*导出*/
    public function export(){
        $input = $this->_auth();
        ClassTransactionDetailModel::index($input);
    }
        /*
     * 处理权限
     */
    private function _auth(){

        $input = request()->all();

        $pfs_dw_id = Auth::pfs([$input['pfs_dw_id']], 0);
        if(empty($pfs_dw_id)){
            throw new APIHttpException('没有权限~');
        }
        /*监管银行账号组*/
        $input['pfs_dw_id'] = explode(',',$pfs_dw_id);

        return $input;
    }
     /*
     * 提交ID
     *    "ids":[
            1,2,3
        ]
     */
     public function push(){
        $ids =  request()->input("ids");
        if(isEmpty($ids)){
            throw new APIHttpException('参数错误~');
        }
        /*判断是否值得推送*/
        if(ClassTransactionDetailModel::isAgreePush($ids)){
            /*循环结果集，存入队列*/
             foreach ($ids as $val){
                PfsHeadAddclassincrementJob::push((int)$val);
            }
        }else{
            //数据存在不等于失败的数据，所以无法推送
            throw new APIHttpException('推送数据不合法~');
        }


        return APIHttpException::success();
    }
}
